package com.jishuo.nontax.bfc.tlq;

import com.jishuo.base.bean.BaseResult;
import com.jishuo.base.config.NonTaxConfig;
import com.jishuo.nontax.bfc.service.ParameterService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Iterator;

@Controller
@RequestMapping(value = "/msgapi")
public class ApiMsgWeb {
    @Resource
    private MessageService messageService;
    @Resource
    private ParameterService parameterService;
    @Resource
    private NonTaxConfig nonTaxConfig;

    @ResponseBody
    @RequestMapping(value = "revMsg")
    public BaseResult revMsg(@RequestBody String data) throws Exception {
        if (nonTaxConfig.DebugType != 2) return BaseResult.CustomErr("不是调试模式，不允许访问");
        if (CertAndQueue.CACERTID == null) {
            parameterService.selectFselecertandqueue();
        }

        Iterator<String> iterator = CertAndQueue.RECEIVEQUEUE.keySet().iterator();
        String queue = "";
        while (iterator.hasNext()) {
            queue = iterator.next();
            break;
        }
        messageService.receiveMessage(queue, "", data, "");
        return new BaseResult();
    }
}
